<?php
########################################################
# DMS Donations Management System v1.0                 #
# created by:  Isaac Sabas                             #
#			   Nikko Reyes							   #
#			   Miko Tiamwatt						   #
#                                                      #
# De La Salle Philippines                              #
# All Rights Reserved DLSP Copyright 2009              #
########################################################

define('START', true);	

session_start();	
		
# set error checking levels #			
	# enable these lines when site is to be deployed #	
	ini_set('error_reporting', E_ALL);
    ini_set('display_errors', 'On');
    //ini_set('log_errors', 'On');
    //ini_set('error_log', '/usr/local/apache/logs/error_log');
	
# include some needed files #
	# include some needed files #
	$absRoot = '../../';
	include($absRoot . 'lib/PEAR/PEAR/Sigma.php');	
	include($absRoot . 'lib/XAJAX/xajax_core/xajax.inc.php');	
	include($absRoot . 'src/AgentHandle.php');
	include($absRoot . 'src/ClientHandle.php');
	include($absRoot . 'src/DBHandle.php');
		
# instantiate predifined classes #
	$template = new HTML_Template_Sigma($absRoot . 'templates', 'templates-cache');	
	$dbConnection = new DBHandle();													
	
# page variables #	
	$page_title = 'De La Salle University | Donations Management System ';								

# load template to buffer #
	$template->loadTemplateFile('contents/dashboardClientList.html');	
	
# process data #
	# check if $_SESSION['agent_id'] is present, this entails that there is an agent logged in. if not present, do not continue
	if ($_SESSION['agentId']) {
		$callListResult = AgentHandle::getCallTaskList($_SESSION['agentId']);
		$dateToday = date("Y-d-m", time());
		$timeToday = time();
		
		foreach ($callListResult as $value) {
			# 1. check if the call status is not closed
				if ($value['call_status'] == 0) {
					$clientFirstName = ClientHandle::getProfileItem('client_firstname', $value['client_id']);
					$clientLastName = ClientHandle::getProfileItem('client_lastname', $value['client_id']);
					$clientMiddleName = ClientHandle::getProfileItem('client_middlename', $value['client_id']);
					$clientType = ClientHandle::getProfileItem('client_type', $value['client_id']);
					
					switch ($clientType) {
						case 0: $clientType = 'Disabled Client'; break;
						case 1: $clientType = 'New Client'; break;
						case 2: $clientType = 'Referred by a client'; break;
						case 3: $clientType = 'Referred'; break;
					}
					
					# 3. set them and parse for every entry
					$template->setVariable('clientId', $value['client_id']);
					$template->setVariable('donationId', $value['donation_id']);	
					$template->setVariable('clientName', $clientFirstName . ' ' . $clientMiddleName . ' ' . $clientLastName);
					$template->setVariable('clientType', $clientType);
					$template->setVariable('callPurpose', $value['call_purpose']);
					$template->setVariable('callPriority', $value['call_priority']);
					$template->setVariable('toCallDate', $value['call_tocalldate']);
					$template->setVariable('toCallTime', date('g:i A',$value['call_tocalltime']));
					# 2. check if the to call date is for today, if not anymore (late) highlight as late
						if ($value['call_tocalldate'] != $dateToday) {
							$template->setVariable('lateCall','[Call was not made on due date]');;
						}
					$template->parse('blockDashboardClientItem');	
				}		
		}
			
	}
	
# set template variables #
	$template->setVariable('PAGE_TITLE', $page_title);	
	$template->setVariable('absRoot', $absRoot);
		
# render the index template #	
	$template->show();	
	
/*
	$client_item_counter = 6;
	$client_item_printer = false;
	$page_counter = 1;
	
	$template->addBlockFile('DASHBOARD_CLIENT_PANEL_PAGE', 'DASHBOARD_CLIENT_PANEL_PAGE', 'dashboard_client_panel.tpl');
	
	while (!$client_item_printer) {								
						
			$template->setVariable('CLIENT_PANEL_PAGE', 'page' . ($page_counter));
			$x = 0;			
			while ($x<5 && !$client_item_printer) {		
				if ($client_item_counter != 0) {
					$template->setVariable('CLIENT_ID', $x);	
					$template->setVariable('CLIENT_NAME', 'Isaac Herculano Sun Sabas');
					$template->parse('dashboard_client_item');	
					$x++;
					$client_item_counter--;				
				}
				else {
					$client_item_printer = true;
				}	
			}		
			$page_counter++;
			$template->parse('DASHBOARD_CLIENT_PANEL_PAGE');				
	}
	
	
	$template->setVariable('CALL_PURPOSE', '1');
	$template->setVariable('CLIENT_ID', '0');	
	$template->setVariable('CLIENT_NAME', 'Pogz Ortile');
	$template->setVariable('CLIENT_CALL_STATUS', 'Pickup Reminder');
	$template->setVariable('TICKET_ID', '1');
	$template->parse('dashboard_client_item');
	
	for ($i=1;$i<9;$i++) {
		$template->setVariable('CALL_PURPOSE', '2');
		$template->setVariable('CLIENT_ID', $i);
		$template->setVariable('TICKET_ID', 'null');	
		$template->setVariable('CLIENT_NAME', 'Isaac Herculano Sun Sabas');
		$template->setVariable('CLIENT_CALL_STATUS', 'For Follow-up');
		$template->parse('dashboard_client_item');	
	}
	*/	
?>
`